
import { getUserInfo,getLogout } from "@/api/api";
import { deleteToken } from "@/utils/uuid_token"
// import router from '@/router'


const state = {
    userInfo: {},
};
const mutations = {
    // 保存用户信息
    SAVEUSERINFO(state, value) {
        state.userInfo = value;
    },
    //清除用户信息
    CLEARUSERINFO(state) {
        state.userInfo = {};
    }
};
const actions = { 
   // 登录请求用户信息
    async saveUserInfo({ commit }) {
      let result = await getUserInfo();
      if (result.code === 200) {
        commit("SAVEUSERINFO", result.data);
        console.log(`获取用户信息成功：${result.message}`);
      } else {
        console.log(`获取用户信息失败：${result.message}`);
      }
    },
    // 退出登录
    async logout({ commit },value) {
      let result = await getLogout();
      if (result.code === 200) {
        value ? this.$message.success("退出登录成功") : "";
        commit("CLEARUSERINFO");
        deleteToken();
        // router.push("/login");
      } else {
       return Promise.reject(new Error(result.message));
      }
    }
};
const getters = { };

export default {
  state,
  mutations,
  actions,
  getters
}